using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.ProductModels 
{
	public partial class ProductModelModel: ModelBase{
		public ProductModelModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.ProductModelID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.Name.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? ProductModelID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_NAME_REQUIRED", ErrorMessageResourceType=typeof(ProductModelResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("NAME", NameResourceType=typeof(ProductModelResources))]
	public String   Name { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[DataType("RichEditorAdvanced")]
	[LocalizedDisplayName("CATALOGDESCRIPTION", NameResourceType=typeof(ProductModelResources))]
	public String   CatalogDescription { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(ProductModelResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(ProductModelResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(ProductModelResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
		
		[LocalizedDisplayName("PRODUCTS", NameResourceType=typeof(ProductModelResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="Products.Count()", ModelPartialType="Products.Product")]
        public List<Products.ProductModel> Products { get; set; }			
	
		[LocalizedDisplayName("PRODUCTMODELPRODUCTDESCRIPTIONS", NameResourceType=typeof(ProductModelResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="ProductModelProductDescriptions.Count()", ModelPartialType="ProductModelProductDescriptions.ProductModelProductDescription")]
        public List<ProductModelProductDescriptions.ProductModelProductDescriptionModel> ProductModelProductDescriptions { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.ProductModelID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"ProductModelID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(ProductModelModel model){
            
		this.ProductModelID = model.ProductModelID;
		this.Name = model.Name;
		this.CatalogDescription = model.CatalogDescription;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.ProductModel GetBusinessObject()
        {
            BusinessObjects.ProductModel result = new BusinessObjects.ProductModel();
	if (this.ProductModelID != null )
				result.ProductModelID = (Int32)this.ProductModelID;
				
	if (this.Name != null )
				result.Name = (String)this.Name.Trim().Replace("\t", String.Empty);
				
	if (this.CatalogDescription != null )
				result.CatalogDescription = (String)this.CatalogDescription.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				



            return result;
        }
        public void Bind(BusinessObjects.ProductModel businessObject)
        {
            
			this.ProductModelID = businessObject.ProductModelID;
				
			this.Name = businessObject.Name != null ? businessObject.Name.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.CatalogDescription != null )
				this.CatalogDescription = (String)businessObject.CatalogDescription;
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
           
        }
	}
}
